<?php
$g4_path = "../"; 
require_once ($g4_path.'common.php');

$title = "선생님 수업 정보";
$menu = 3;
require_once ('./admin.head.php');
require_once ('./admin.lib.php');

$_GET['year'] = isset($_GET['year'])? $_GET['year'] : date('Y');
$_GET['month'] = isset($_GET['month'])? $_GET['month'] : date('n');

$where = '';
if(isset($_GET['name'])) {
$where = "AND mb_name like '%".addslashes($_GET['name'])."%'";
}
$sql = "SELECT count(1) FROM (SELECT mb_no, mb_name, mb_tel, mb_hp FROM g4_member g, course c WHERE g.mb_division = '강사' AND c.year = {$_GET['year']} AND  c.month = {$_GET['month']} AND c.teacher = g.mb_no  $where group by mb_no) as a";
$page = isset($_GET['page'])? $_GET['page']: 1;
list($totalCount) = mysql_fetch_array(mysql_query($sql));
$count = $totalCount - ($page - 1) * 20;
$limitSQL = getLimit();
$sql = "SELECT mb_no, mb_name, mb_tel, mb_hp FROM g4_member g, course c WHERE g.mb_division = '강사' AND c.year = {$_GET['year']} AND  c.month = {$_GET['month']} AND c.teacher = g.mb_no  $where group by mb_no $limitSQL";
$res = mysql_query($sql);

$data = array();
while($temp = mysql_fetch_assoc($res)) {
        $sql = "SELECT count(1) from course_order o, course c WHERE c.teacher = {$temp['mb_no']} AND o.status = 2 AND o.course = c.no AND c.year = {$_GET['year']} AND  c.month = {$_GET['month']}";
        list($temp['studentCount']) =  mysql_fetch_row(mysql_query($sql));
        $sql = "SELECT count(1) from course WHERE teacher = {$temp['mb_no']} AND year = {$_GET['year']} AND  month = {$_GET['month']} ";
        list($temp['courseCount']) = mysql_fetch_array(mysql_query($sql));
        $sql = "SELECT w_mon+w_tue+w_wed+w_thu+w_fri+w_sat from course WHERE teacher = {$temp['mb_no']} AND year = {$_GET['year']} AND  month = {$_GET['month']} ";
        list($temp['week']) = mysql_fetch_array(mysql_query($sql));
        $temp['week'] = $temp['week']? $temp['week'] : 0;
        $temp['month'] = $temp['week'] * 4;
        $temp['count'] = $count--;
        $data[] = $temp;
}

$thisYear = date('Y');
for($i = 2008; $i <= $thisYear+1; $i++) {
        $years[$i]= array('y' => "{$i}년");
        if($i == $_GET['year']) {
            $years[$i]['s'] = 'selected="selected"';
        }
}

$monthSelected = array($_GET['month']=>'selected="selected"');


$pager = getPager($totalCount);
$tpl->define('basic',"teacherCourseManage.html");
$tpl->print_('basic');

require_once('admin.foot.php');
